package com.fangsheng.netty.netty.http;

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;

/**
 * @创建人: 放生
 * @创建时间: 2022/2/21
 * @描述: netty 作为http服务端的案列
 * 1)实例要求：使用IDEA创建Netty项目
 * 2)Netty服务器在8087端口监听，浏览器发出请求"http://localhost:8087/"
 * 3)服务器可以回复消息给客户端"Hello!我是服务器5",并对特定请求资源进行过滤.
 * 4)目的：Netty可以做Http服务开发，并且理解Handler实例和客户端及其请求的关系.
 */
public class TestServer {

    public static void main(String[] args) throws Exception{

        EventLoopGroup bossGroup = new NioEventLoopGroup(1);
        EventLoopGroup workerGroup = new NioEventLoopGroup();

        try {
            ServerBootstrap serverBootstrap = new ServerBootstrap();

            serverBootstrap.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class).childHandler(new TestServerInitializer());

            ChannelFuture channelFuture = serverBootstrap.bind(8087).sync();

            channelFuture.channel().closeFuture().sync();

        }finally {
            bossGroup.shutdownGracefully();
            workerGroup.shutdownGracefully();
        }


    }



}
